// 技能三选一
// @author: wangff8@qq.com  @date:2024-10-29
library ChooseSkillUI initializer init requires UIInit, SkillVo, RandomSkillSys

    // 初始化创建UI
    private function create takes nothing returns nothing
        local integer ui = StringHash("技能三选一")
        local integer i
        local integer i2

        // 第一个按钮背景
        set i = 0
        call SaveInteger(UI_HASH, ui, i, DzCreateFrameByTagName("BACKDROP", "背景", DzGetGameUI(), "BACKDROP", 0))
        call DzFrameSetAbsolutePoint( LoadInteger(UI_HASH, ui, i), 4, 0.256, 0.35 )
        call DzFrameSetTexture( LoadInteger(UI_HASH, ui, i), "bg_baow_xz.tga", 0 )
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i), 287.0 / 2400.0, 458.0 / 1800.0 )
        call DzFrameShow( LoadInteger(UI_HASH, ui, i), false )
        // 头像
        set i2 = i + 10
        call SaveInteger(UI_HASH, ui, i2, DzCreateFrameByTagName("BACKDROP", "name", LoadInteger(UI_HASH, ui, i), "template", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i2), 0.030, 0.030 )
        call DzFrameSetTexture( LoadInteger(UI_HASH, ui, i2), "ReplaceableTextures\\CommandButtons\\BTNPeasant.blp", 0 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i2), 1, LoadInteger(UI_HASH, ui, i), 1, 0, -0.04 )
        // 名称
        set i2 = i + 20
        call SaveInteger(UI_HASH, ui, i2, DzCreateFrameByTagName("TEXT", "name", LoadInteger(UI_HASH, ui, i), "UI_TEXT_12_TOP", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i2), 0.1027552, 0.00 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i2), 0, LoadInteger(UI_HASH, ui, i), 0, 0.01, -0.080 )
        call DzFrameSetText( LoadInteger(UI_HASH, ui, i2), "|cffffffcc仙人|r" )
        // 介绍内容
        set i2 = i + 30
        call SaveInteger(UI_HASH, ui, i2, DzCreateFrameByTagName("TEXT", "name", LoadInteger(UI_HASH, ui, i), "UI_TEXT_9_TOPLEFT", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i2), 0.1027552, 0.00 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i2), 0, LoadInteger(UI_HASH, ui, i), 0, 0.015, -0.10 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i2), 8, LoadInteger(UI_HASH, ui, i), 8, -0.015, -0.02 )
        call DzFrameSetText( LoadInteger(UI_HASH, ui, i2), "内容介绍" )
        set i2 = i + 200
        call SaveInteger(UI_HASH, ui, i2, DzCreateFrameByTagName("GLUEBUTTON", "name", LoadInteger(UI_HASH, ui, i), "template", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i2), 287.0 / 2400.0, 458.0 / 1800.0 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i2), 4, LoadInteger(UI_HASH, ui, i), 4, 0, 0.0 )
        // 点击事件
        call DzFrameSetScript(LoadInteger(UI_HASH, ui, i2), 1, "CEBwItem", false)
        // 鼠标进入事件
        call DzFrameSetScript(LoadInteger(UI_HASH, ui, i2), 2, "IEBwItem", false)
        // 鼠标离开事件
        call DzFrameSetScript(LoadInteger(UI_HASH, ui, i2), 3, "OEBwItem", false)


        // 第二个按钮
        set i = 1
        call SaveInteger(UI_HASH, ui, i, DzCreateFrameByTagName("BACKDROP", "背景", DzGetGameUI(), "BACKDROP", 0))
        call DzFrameSetAbsolutePoint( LoadInteger(UI_HASH, ui, i), 4, 0.256 + 0.150, 0.35 )
        call DzFrameSetTexture( LoadInteger(UI_HASH, ui, i), "bg_baow_xz.tga", 0 )
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i), 287.0 / 2400.0, 458.0 / 1800.0 )
        call DzFrameShow( LoadInteger(UI_HASH, ui, i), false )
        // 头像
        set i2 = i + 10
        call SaveInteger(UI_HASH, ui, i2, DzCreateFrameByTagName("BACKDROP", "name", LoadInteger(UI_HASH, ui, i), "template", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i2), 0.030, 0.030 )
        call DzFrameSetTexture( LoadInteger(UI_HASH, ui, i2), "ReplaceableTextures\\CommandButtons\\BTNPeasant.blp", 0 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i2), 1, LoadInteger(UI_HASH, ui, i), 1, 0, -0.04 )
        // 名称
        set i2 = i + 20
        call SaveInteger(UI_HASH, ui, i2, DzCreateFrameByTagName("TEXT", "name", LoadInteger(UI_HASH, ui, i), "UI_TEXT_12_TOP", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i2), 0.1027552, 0.00 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i2), 0, LoadInteger(UI_HASH, ui, i), 0, 0.01, -0.080 )
        call DzFrameSetText( LoadInteger(UI_HASH, ui, i2), "|cffffffcc仙人|r" )
        // 介绍内容
        set i2 = i + 30
        call SaveInteger(UI_HASH, ui, i2, DzCreateFrameByTagName("TEXT", "name", LoadInteger(UI_HASH, ui, i), "UI_TEXT_9_TOPLEFT", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i2), 0.1027552, 0.00 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i2), 0, LoadInteger(UI_HASH, ui, i), 0, 0.015, -0.10 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i2), 8, LoadInteger(UI_HASH, ui, i), 8, -0.015, -0.02 )
        call DzFrameSetText( LoadInteger(UI_HASH, ui, i2), "内容介绍" )
        set i2 = i + 200
        call SaveInteger(UI_HASH, ui, i2, DzCreateFrameByTagName("GLUEBUTTON", "name", LoadInteger(UI_HASH, ui, i), "template", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i2), 287.0 / 2400.0, 458.0 / 1800.0 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i2), 4, LoadInteger(UI_HASH, ui, i), 4, 0, 0.0 )
        // 点击事件
        call DzFrameSetScript(LoadInteger(UI_HASH, ui, i2), 1, "CEBwItem", false)
        // 鼠标进入事件
        call DzFrameSetScript(LoadInteger(UI_HASH, ui, i2), 2, "IEBwItem", false)
        // 鼠标离开事件
        call DzFrameSetScript(LoadInteger(UI_HASH, ui, i2), 3, "OEBwItem", false)

        // 第三个按钮
        set i = 2
        call SaveInteger(UI_HASH, ui, i, DzCreateFrameByTagName("BACKDROP", "背景", DzGetGameUI(), "BACKDROP", 0))
        call DzFrameSetAbsolutePoint( LoadInteger(UI_HASH, ui, i), 4, 0.256 + 0.150 + 0.150, 0.35 )
        call DzFrameSetTexture( LoadInteger(UI_HASH, ui, i), "bg_baow_xz.tga", 0 )
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i), 287.0 / 2400.0, 458.0 / 1800.0 )
        call DzFrameShow( LoadInteger(UI_HASH, ui, i), false )
        // 头像
        set i2 = i + 10
        call SaveInteger(UI_HASH, ui, i2, DzCreateFrameByTagName("BACKDROP", "name", LoadInteger(UI_HASH, ui, i), "template", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i2), 0.030, 0.030 )
        call DzFrameSetTexture( LoadInteger(UI_HASH, ui, i2), "ReplaceableTextures\\CommandButtons\\BTNPeasant.blp", 0 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i2), 1, LoadInteger(UI_HASH, ui, i), 1, 0, -0.04 )
        // 名称
        set i2 = i + 20
        call SaveInteger(UI_HASH, ui, i2, DzCreateFrameByTagName("TEXT", "name", LoadInteger(UI_HASH, ui, i), "UI_TEXT_12_TOP", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i2), 0.1027552, 0.00 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i2), 0, LoadInteger(UI_HASH, ui, i), 0, 0.01, -0.080 )
        call DzFrameSetText( LoadInteger(UI_HASH, ui, i2), "|cffffffcc仙人|r" )
        // 介绍内容
        set i2 = i + 30
        call SaveInteger(UI_HASH, ui, i2, DzCreateFrameByTagName("TEXT", "name", LoadInteger(UI_HASH, ui, i), "UI_TEXT_9_TOPLEFT", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i2), 0.1027552, 0.00 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i2), 0, LoadInteger(UI_HASH, ui, i), 0, 0.015, -0.10 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i2), 8, LoadInteger(UI_HASH, ui, i), 8, -0.015, -0.02 )
        call DzFrameSetText( LoadInteger(UI_HASH, ui, i2), "内容介绍" )
        set i2 = i + 200
        call SaveInteger(UI_HASH, ui, i2, DzCreateFrameByTagName("GLUEBUTTON", "name", LoadInteger(UI_HASH, ui, i), "template", 0))
        call DzFrameSetSize( LoadInteger(UI_HASH, ui, i2), 287.0 / 2400.0, 458.0 / 1800.0 )
        call DzFrameSetPoint( LoadInteger(UI_HASH, ui, i2), 4, LoadInteger(UI_HASH, ui, i), 4, 0, 0.0 )
        // 点击事件
        call DzFrameSetScript(LoadInteger(UI_HASH, ui, i2), 1, "CEBwItem", false)
        // 鼠标进入事件
        call DzFrameSetScript(LoadInteger(UI_HASH, ui, i2), 2, "IEBwItem", false)
        // 鼠标离开事件
        call DzFrameSetScript(LoadInteger(UI_HASH, ui, i2), 3, "OEBwItem", false)
    endfunction

    // 鼠标点击
    function CEBwItem takes nothing returns nothing
        local integer uid = GetPlayerId(DzGetTriggerUIEventPlayer())
        local integer ui = StringHash("技能三选一")
        local integer i

        call DzFrameShow( LoadInteger(UI_HASH, ui, 0), false )
        call DzFrameShow( LoadInteger(UI_HASH, ui, 1), false )
        call DzFrameShow( LoadInteger(UI_HASH, ui, 2), false )
        set i = 0
        loop
            exitwhen i > 2
            if DzGetTriggerUIEventFrame() == LoadInteger(UI_HASH, ui, i + 200) then
                call DzSyncData( "UI_Feng_SysnData", "aaa" + I2S(cardSkillId[uid * 8 + i]) + "-" + I2S(cardSkillIdSmall[uid * 8 + i]) )
            endif
            set i = i + 1
        endloop
    endfunction

    // 鼠标进入
    function IEBwItem takes nothing returns nothing
        local integer uid = GetPlayerId(DzGetTriggerUIEventPlayer())
        local integer ui = StringHash("技能三选一")
        local integer i
        local integer pKey

        set i = 0
        loop
            exitwhen i > 2
            if DzGetTriggerUIEventFrame() == LoadInteger(UI_HASH, ui, i + 200) then
                call DzFrameSetTexture( LoadInteger(UI_HASH, ui, i), "bg_baow_xz_x.tga", 0 )
                // set pKey = chooseSKIds[uid * 5 + i]
                // call DzFrameShow( LoadInteger(UI_HASH, ui, i + 100), true )
                // call showTipWithDataPanel(uid, LoadStr(eliteUIHash, pKey, 3), LoadStr(eliteUIHash, pKey, 4), LoadStr(eliteUIHash, pKey, 5), LoadStr(eliteUIHash, pKey, 6), LoadStr(eliteUIHash, pKey, 7), DzGetTriggerUIEventFrame())
            endif
            set i = i + 1
        endloop
    endfunction

    // 鼠标离开
    function OEBwItem takes nothing returns nothing
        local integer uid = GetPlayerId(DzGetTriggerUIEventPlayer())
        local integer ui = StringHash("技能三选一")
        local integer i

        set i = 0
        loop
            exitwhen i > 2

            if DzGetTriggerUIEventFrame() == LoadInteger(UI_HASH, ui, i + 200) then
                call DzFrameSetTexture( LoadInteger(UI_HASH, ui, i), "bg_baow_xz.tga", 0 )
                // call DzFrameShow( LoadInteger(UI_HASH, ui, i + 100), false )
            endif
            set i = i + 1
        endloop

        // call hideTipWithDataPanel()
    endfunction


    // ======================= 业务逻辑 =======================
    // 显示UI
    function skillShowChooseIcoUI takes integer uid, integer level returns nothing

        local integer ui = StringHash("技能三选一")
        local integer i
        local integer i2

        call randomSkillId(uid)
        // 第一个随机的
        set i = 0
        if Player(uid) == GetLocalPlayer() then
            // 设置图标
            set i2 = i + 10
            call DzFrameSetTexture( LoadInteger(UI_HASH, ui, i2), getSkillIcon(cardSkillId[uid * 8 + i], cardSkillIdSmall[uid * 8 + i]), 0 )
            // 设置名称
            set i2 = i + 20
            if cardSkillId[uid * 8 + i] != 1 and cardSkillIdSmall[uid * 8 + i] == 1 then
                call DzFrameSetText( LoadInteger(UI_HASH, ui, i2), getSkillName(cardSkillId[uid * 8 + i], cardSkillIdSmall[uid * 8 + i]) + "（|cffff0000新|r）" )
            else
                call DzFrameSetText( LoadInteger(UI_HASH, ui, i2), getSkillName(cardSkillId[uid * 8 + i], cardSkillIdSmall[uid * 8 + i]) )
            endif
            // 设置描述
            set i2 = i + 30
            call DzFrameSetText( LoadInteger(UI_HASH, ui, i2), getSkillInstro(cardSkillId[uid * 8 + i], cardSkillIdSmall[uid * 8 + i]) )
        endif

        // 第二个
        set i = 1
        if Player(uid) == GetLocalPlayer() then
            // 设置图标
            set i2 = i + 10
            call DzFrameSetTexture( LoadInteger(UI_HASH, ui, i2), getSkillIcon(cardSkillId[uid * 8 + i], cardSkillIdSmall[uid * 8 + i]), 0 )
            // 设置名称
            set i2 = i + 20
            if cardSkillId[uid * 8 + i] != 1 and cardSkillIdSmall[uid * 8 + i] == 1 then
                call DzFrameSetText( LoadInteger(UI_HASH, ui, i2), getSkillName(cardSkillId[uid * 8 + i], cardSkillIdSmall[uid * 8 + i]) + "（|cffff0000新|r）" )
            else
                call DzFrameSetText( LoadInteger(UI_HASH, ui, i2), getSkillName(cardSkillId[uid * 8 + i], cardSkillIdSmall[uid * 8 + i]) )
            endif
            // 设置描述
            set i2 = i + 30
            call DzFrameSetText( LoadInteger(UI_HASH, ui, i2), getSkillInstro(cardSkillId[uid * 8 + i], cardSkillIdSmall[uid * 8 + i]) )
        endif

        // 第三个
        set i = 2
        if Player(uid) == GetLocalPlayer() then
            // 设置图标
            set i2 = i + 10
            call DzFrameSetTexture( LoadInteger(UI_HASH, ui, i2), getSkillIcon(cardSkillId[uid * 8 + i], cardSkillIdSmall[uid * 8 + i]), 0 )
            // 设置名称
            set i2 = i + 20
            if cardSkillId[uid * 8 + i] != 1 and cardSkillIdSmall[uid * 8 + i] == 1 then
                call DzFrameSetText( LoadInteger(UI_HASH, ui, i2), getSkillName(cardSkillId[uid * 8 + i], cardSkillIdSmall[uid * 8 + i]) + "（|cffff0000新|r）" )
            else
                call DzFrameSetText( LoadInteger(UI_HASH, ui, i2), getSkillName(cardSkillId[uid * 8 + i], cardSkillIdSmall[uid * 8 + i]) )
            endif
            // 设置描述
            set i2 = i + 30
            call DzFrameSetText( LoadInteger(UI_HASH, ui, i2), getSkillInstro(cardSkillId[uid * 8 + i], cardSkillIdSmall[uid * 8 + i]) )
        endif

        if Player(uid) == GetLocalPlayer() then
            call DzFrameShow( LoadInteger(UI_HASH, ui, 0), true )
            call DzFrameShow( LoadInteger(UI_HASH, ui, 1), true )
            call DzFrameShow( LoadInteger(UI_HASH, ui, 2), true )
        endif
    endfunction

    private function init takes nothing returns nothing
        call create()
    endfunction
endlibrary




